<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="开始时间">
              <j-date placeholder="请选择开始时间" v-model="queryParam.startDate"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结束时间">
              <j-date placeholder="请选择创建时间" v-model="queryParam.endDate"></j-date>
            </a-form-item>
          </a-col>
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="任务编号">-->
<!--              <a-input placeholder="请输入任务编号" v-model="queryParam.taskNo"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="任务名称">-->
<!--              <a-input placeholder="请输入任务名称" v-model="queryParam.taskName"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="任务状态">-->
<!--              <j-dict-select-tag placeholder="请选择任务状态" v-model="queryParam.taskStatus" dictCode="task_status"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <template v-if="toggleSearchStatus">-->
<!--            <a-col :xl="10" :lg="11" :md="12" :sm="24">-->
<!--              <a-form-item label="开始时间">-->
<!--                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.taskBegin_begin"></j-date>-->
<!--                <span class="query-group-split-cust"></span>-->
<!--                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.taskBegin_end"></j-date>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--            <a-col :xl="10" :lg="11" :md="12" :sm="24">-->
<!--              <a-form-item label="结束时间">-->
<!--                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.taskEnd_begin"></j-date>-->
<!--                <span class="query-group-split-cust"></span>-->
<!--                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.taskEnd_end"></j-date>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--          </template>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
<!--      <a-button type="primary" icon="download" @click="handleExportXls('任务')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="toBeInspectedNumSlot" slot-scope="text,record">
          <span>{{ record.pointNum - record.inspectedNum }}</span>
        </template>

        <template slot="taskStatusSlot" slot-scope="text,record">
          <span v-has="'task_status'">{{ record.taskStatus_dictText }}</span>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="任务项" key="1" >
        <InsTaskItemList_report :mainId="insTaskItemMainId" />
      </a-tab-pane>
    </a-tabs>

<!--    <insTask-modal ref="modalForm" @ok="modalFormOk"></insTask-modal>-->
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  // import InsTaskModal from './modules/InsTaskModal'
  import { getAction } from '@/api/manage'
  import InsTaskItemList_report from './InsTaskItemList_report'
  import {initDictOptions,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "InsTaskList_report",
    mixins:[JeecgListMixin],
    components: {
      InsTaskItemList_report,
      // InsTaskModal
    },
    data () {
      return {
        description: '任务管理页面',
        // 表头
        columns: [
          {
            title:'班次',
            align:"center",
            dataIndex: 'classId_dictText'
          },
          {
            title:'任务编号',
            align:"center",
            dataIndex: 'taskNo'
          },
          {
            title:'任务名称',
            align:"center",
            dataIndex: 'taskName',
          },
          {
            title:'任务状态',
            align:"center",
            dataIndex: 'taskStatus_dictText',
            scopedSlots: { customRender: 'taskStatusSlot' }
          },
          {
            title:'任务类型',
            align:"center",
            dataIndex: 'taskClass_dictText'
          },
          {
            title:'巡检异常通知',
            align:"center",
            dataIndex: 'errInfo'
          },
          {
            title:'执行周期',
            align:"center",
            dataIndex: 'executeCycle_dictText',
          },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'taskBegin',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'结束时间',
            align:"center",
            dataIndex: 'taskEnd',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'打卡签到起始时间',
            align:"center",
            dataIndex: 'classTimePre'
          },
          {
            title:'打卡签到结束时间',
            align:"center",
            dataIndex: 'classTimeEnd'
          },
          {
            title:'待巡检数',
            align:"center",
            dataIndex: 'toBeInspectedNum',
            scopedSlots: {customRender: "toBeInspectedNumSlot"}
          },
          {
            title:'已巡检数',
            align:"center",
            dataIndex: 'inspectedNum'
          },
          {
            title:'总点位数',
            align:"center",
            dataIndex: 'pointNum'
          },
          // {
          //   title:'规则',
          //   align:"center",
          //   dataIndex: 'ruleId_dictText',
          // },
          // {
          //   title:'角色',
          //   align:"center",
          //   dataIndex: 'roleId_dictText',
          // },
          // {
          //   title:'部门',
          //   align:"center",
          //   dataIndex: 'deptId_dictText',
          // },
          // {
          //   title:'人员',
          //   align:"center",
          //   dataIndex: 'userId'
          // },
          // {
          //   title:'执行人',
          //   align:"center",
          //   dataIndex: 'executor'
          // },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' },
          // }
        ],
        url: {
          list: "/inspect/insTask/listReport",
          delete: "/inspect/insTask/delete",
          deleteBatch: "/inspect/insTask/deleteBatch",
          exportXlsUrl: "/inspect/insTask/exportXls",
          importExcelUrl: "inspect/insTask/importExcel",
        },
        dictOptions:{
         taskStatus:[],
         ruleId:[],
         roleId:[],
         deptId:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        superFieldList:[],
        insTaskItemMainId: '',
      }
    },
    created() {
      this.getSuperFieldList();
    },
		mounted() {
		},
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
        initDictOptions('sys_depart,depart_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'deptId', res.result)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.insTaskItemMainId = selectionRows[0]['id']
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
				if(this.$route.query&&this.$route.query.status){
					this.queryParam.taskStatus=this.$route.query.status
					params.taskStatus = this.$route.query.status

					let str = this.$route.query.month;
          if(str) {
            let secondEnd = Number(str.substring(0,3))%4==0?'29':'28'

            var endDay = ['','31',secondEnd,'31','30','31','30','31','31','30','31','30','31'];
            // 2023-12-14
            this.queryParam.taskBegin_begin = str.substring(0,4) + '-'+str.substring(4,6) + '-' + '01'
            this.queryParam.taskBegin_end = str.substring(0,4) + '-' +str.substring(4,6) + '-' + endDay[str.substring(4,6)]
            this.queryParam.taskEnd_begin = str.substring(0,4) + '-' +str.substring(4,6) + '-' + '01'
            this.queryParam.taskEnd_end = str.substring(0,4) + '-' +str.substring(4,6) + '-' + endDay[str.substring(4,6)]
            params.taskBegin_begin = this.queryParam.taskBegin_begin
            params.taskBegin_end = this.queryParam.taskBegin_end
            params.taskEnd_begin = this.queryParam.taskEnd_begin
            params.taskEnd_end = this.queryParam.taskEnd_end
          }

          let departId = this.$route.query.departId;
          if(departId) {
            this.queryParam.deptId = departId;
            params.deptId = departId;
          }

          let roleId = this.$route.query.roleId;
          if(roleId) {
            this.queryParam.roleId = roleId;
            params.roleId = roleId;
          }

        }
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'taskNo',text:'任务编号',dictCode:''})
        fieldList.push({type:'string',value:'taskStatus',text:'任务状态',dictCode:'task_status'})
        fieldList.push({type:'date',value:'taskBegin',text:'开始时间'})
        fieldList.push({type:'date',value:'taskEnd',text:'结束时间'})
        fieldList.push({type:'int',value:'inspectedNum',text:'已巡检数',dictCode:''})
        fieldList.push({type:'int',value:'pointNum',text:'总点位数',dictCode:''})
        fieldList.push({type:'string',value:'ruleId',text:'规则',dictCode:"ins_rule,rule_name,id"})
        fieldList.push({type:'string',value:'roleId',text:'角色',dictCode:"sys_role,role_name,id"})
        fieldList.push({type:'sel_depart',value:'deptId',text:'部门'})
        fieldList.push({type:'sel_user',value:'userId',text:'人员'})
        fieldList.push({type:'string',value:'executor',text:'执行人',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
